var levelOrder = function(root) {
    let res = []
    if(root==null)return res
    const p = []
    p.push(root)
    while(p.length){
        res.push([])
        let le = p.length
        for(let i=0;i<le;i++){
            root = p.shift()
            res[length-1].push(root.val)
            if(root.left) p.push(root.left)
            if(root.right) p.push(root.right)
        }
    }
    return res
};